<?php

/**
 * client filter form base class.
 *
 * @package    e-DSL
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseclientFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'datecreation'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'code'                  => new sfWidgetFormFilterInput(),
      'categorieclient_id'    => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('categorieclient'), 'add_empty' => true)),
      'nom'                   => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'forme_juridique_id'    => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('forme_juridique'), 'add_empty' => true)),
      'commercial_id'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('commercial'), 'add_empty' => true)),
      'adresse'               => new sfWidgetFormFilterInput(),
      'codpos'                => new sfWidgetFormFilterInput(),
      'ville'                 => new sfWidgetFormFilterInput(),
      'departement_id'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('departement'), 'add_empty' => true)),
      'telephone'             => new sfWidgetFormFilterInput(),
      'fax'                   => new sfWidgetFormFilterInput(),
      'email'                 => new sfWidgetFormFilterInput(),
      'web'                   => new sfWidgetFormFilterInput(),
      'activite_id'           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('activite'), 'add_empty' => true)),
      'reseau_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('reseau'), 'add_empty' => true)),
      'siret'                 => new sfWidgetFormFilterInput(),
      'encour'                => new sfWidgetFormFilterInput(),
      'delais_paiement_id'    => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('delais_paiement'), 'add_empty' => true)),
      'dirigeant'             => new sfWidgetFormFilterInput(),
      'fonction_dirigeant_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('fonction_dirigeant'), 'add_empty' => true)),
      'contactes_id'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('contactes'), 'add_empty' => true)),
      'remises_id'            => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('remises'), 'add_empty' => true)),
      'codes_id'              => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('codes'), 'add_empty' => true)),
      'concurrents_id'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('concurrents'), 'add_empty' => true)),
      'observations'          => new sfWidgetFormFilterInput(),
      'longitude'             => new sfWidgetFormFilterInput(),
      'latitude'              => new sfWidgetFormFilterInput(),
      'location_type'         => new sfWidgetFormFilterInput(),
      'address_type'          => new sfWidgetFormFilterInput(),
      'external_id'           => new sfWidgetFormFilterInput(),
      'activeStatus'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'created_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'            => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'fournisseurs_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'fournisseur')),
    ));

    $this->setValidators(array(
      'datecreation'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'code'                  => new sfValidatorPass(array('required' => false)),
      'categorieclient_id'    => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('categorieclient'), 'column' => 'id')),
      'nom'                   => new sfValidatorPass(array('required' => false)),
      'forme_juridique_id'    => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('forme_juridique'), 'column' => 'id')),
      'commercial_id'         => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('commercial'), 'column' => 'id')),
      'adresse'               => new sfValidatorPass(array('required' => false)),
      'codpos'                => new sfValidatorPass(array('required' => false)),
      'ville'                 => new sfValidatorPass(array('required' => false)),
      'departement_id'        => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('departement'), 'column' => 'id')),
      'telephone'             => new sfValidatorPass(array('required' => false)),
      'fax'                   => new sfValidatorPass(array('required' => false)),
      'email'                 => new sfValidatorPass(array('required' => false)),
      'web'                   => new sfValidatorPass(array('required' => false)),
      'activite_id'           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('activite'), 'column' => 'id')),
      'reseau_id'             => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('reseau'), 'column' => 'id')),
      'siret'                 => new sfValidatorPass(array('required' => false)),
      'encour'                => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'delais_paiement_id'    => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('delais_paiement'), 'column' => 'id')),
      'dirigeant'             => new sfValidatorPass(array('required' => false)),
      'fonction_dirigeant_id' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('fonction_dirigeant'), 'column' => 'id')),
      'contactes_id'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('contactes'), 'column' => 'id')),
      'remises_id'            => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('remises'), 'column' => 'id')),
      'codes_id'              => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('codes'), 'column' => 'id')),
      'concurrents_id'        => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('concurrents'), 'column' => 'id')),
      'observations'          => new sfValidatorPass(array('required' => false)),
      'longitude'             => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'latitude'              => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'location_type'         => new sfValidatorPass(array('required' => false)),
      'address_type'          => new sfValidatorPass(array('required' => false)),
      'external_id'           => new sfValidatorPass(array('required' => false)),
      'activeStatus'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'            => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'            => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'fournisseurs_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'fournisseur', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('client_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addFournisseursListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.client_fournisseur_fournisseurs_link client_fournisseur_fournisseurs_link')
      ->andWhereIn('client_fournisseur_fournisseurs_link.owner_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'client';
  }

  public function getFields()
  {
    return array(
      'id'                    => 'Number',
      'datecreation'          => 'Date',
      'code'                  => 'Text',
      'categorieclient_id'    => 'ForeignKey',
      'nom'                   => 'Text',
      'forme_juridique_id'    => 'ForeignKey',
      'commercial_id'         => 'ForeignKey',
      'adresse'               => 'Text',
      'codpos'                => 'Text',
      'ville'                 => 'Text',
      'departement_id'        => 'ForeignKey',
      'telephone'             => 'Text',
      'fax'                   => 'Text',
      'email'                 => 'Text',
      'web'                   => 'Text',
      'activite_id'           => 'ForeignKey',
      'reseau_id'             => 'ForeignKey',
      'siret'                 => 'Text',
      'encour'                => 'Number',
      'delais_paiement_id'    => 'ForeignKey',
      'dirigeant'             => 'Text',
      'fonction_dirigeant_id' => 'ForeignKey',
      'contactes_id'          => 'ForeignKey',
      'remises_id'            => 'ForeignKey',
      'codes_id'              => 'ForeignKey',
      'concurrents_id'        => 'ForeignKey',
      'observations'          => 'Text',
      'longitude'             => 'Number',
      'latitude'              => 'Number',
      'location_type'         => 'Text',
      'address_type'          => 'Text',
      'external_id'           => 'Text',
      'activeStatus'          => 'Number',
      'created_at'            => 'Date',
      'updated_at'            => 'Date',
      'fournisseurs_list'     => 'ManyKey',
    );
  }
}
